<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class Recharge extends Model
{
    protected $table = 'recharges';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'userid',
        'money',
        'fee',
        'actualmoney',
        'status',
        'path',
        'rechargenumber',
        'doublemoney',
        'doublestatus',
        'isdoublecoupons',
        'doubletime',
        'sharestatus',
        'note',
        'adminid',
    ];

    public static function doubleModel($userid)
    {
        $double = Recharge::where(array('userid'=>$userid,'doublestatus'=>0))->get();
        foreach ($double as $v) {
            if(strtotime($v['doubletime']) <= time()) {
                $recharge = Recharge::find($v["id"]);
                $recharge->doublestatus = '1';
                $recharge->save();
                User::find($v['userid'])->increment('balance',$v["doublemoney"]);
                User::find($v['userid'])->increment('point',$v["money"]);
            }
        }
        return true;
    }
}
